<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>PalyPro登录</title>
    <link rel="stylesheet" type="text/css" th:href="@{/pubilc/plugin/layui/css/layui.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/pubilc/plugin/css/login.css}"/>
    <script th:src="@{/pubilc/plugin/layui/layui.js}" type="text/javascript" charset="utf-8"></script>

</head>

<body>
<!--<p th:text="${hello}"></p>-->
<div class="m-login-bg">
    <div class="m-login">
        <h3>PalyPro登录</h3>
        <div class="m-login-warp">
            <form class="layui-form">
                <div class="layui-form-item">
                    <input type="text" name="userName" required="required" lay-verify="required" placeholder="用户名"
                           autocomplete="off"
                           class="layui-input"/>
                </div>
                <div class="layui-form-item">
                    <input type="password" name="password" required="required" lay-verify="required" placeholder="密码"
                           autocomplete="off" class="layui-input"/>
                </div>
                <div class="layui-form-item m-login-btn">
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="login">登录</button>
                    </div>
                    <div class="layui-inline">
                        <button type="reset" class="layui-btn layui-btn-primary">取消</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <script type="text/javascript" th:inline="javascript">
        /*<![CDATA[*/
        var basePath = /*[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]*/;
        /*]]>*/
    </script>

    <script>

        if (window.frames.length != parent.frames.length) {
            top.location.href = location.href;
        }

        layui.use(['form', 'layedit', 'laydate', 'jquery'], function () {
            var form = layui.form,
                layer = layui.layer;
            var $ = layui.jquery;

            //自定义验证规则
            form.verify({
                title: function (value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                },
                password: [/(.+){6,12}$/, '密码必须6到12位'],
                verity: [/(.+){6}$/, '验证码必须是6位'],

            });


            //监听提交
            form.on('submit(login)', function (data) {

                $.ajax({
                    url: basePath + '/play/page/login',
                    type: 'POST',
                    data: data.field,
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 1) {
                            layer.alert(data.msg);
                        } else if (data.code == 0) {
                            window.location.href = basePath + "/play/page/index";
                        }

                    }
                });


                return false;
            });

        });
    </script>
</div>
</body>

</html>